package view;

import java.awt.Color;
import java.awt.Dimension;
//import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.Database;
import controller.ActionHomeProfile;
import controller.Engine;

@SuppressWarnings("serial")
public class HomeProfile extends JPanel implements Observer{
	JPanel profile = new JPanel();
	static ActionListener action = new ActionHomeProfile();

	public HomeProfile(){
		profile = this;
		Database.Utente.addObserver(this);
		startHomeProfile();

	}
	public void startHomeProfile() {
		profile.setBackground(Color.white);
		JPanel div = new JPanel();
		div.setBackground(Color.white);
		JButton photo = new JButton();
		JButton gestAccount = new JButton("Account");
		JButton logout = new JButton(" Logout ");
		photo.setName("photo");
		gestAccount.setName("account");
		logout.setName("logout");
		photo.addActionListener(action);
		gestAccount.addActionListener(action);
		logout.addActionListener(action);
		JLabel image = new JLabel();
		JPanel un = new JPanel();
		un.setBackground(Color.white);
		JLabel username = new JLabel();
		JLabel sector =new JLabel();
		JPanel anag = new JPanel();
		anag.setBackground(Color.white);
		JLabel anagrafica = new JLabel();
		JLabel flab = new JLabel();

		//System.out.println(Database.Utente.getPhoto());
		image = Engine.setImage(Database.Utente.getPhoto(),140,140);
		photo.add(image);
		photo.setContentAreaFilled(false);

		username.setText("Ruolo:");
		sector.setText(Database.Utente.getSector());
		un.setLayout(new BoxLayout(un,BoxLayout.Y_AXIS));
		un.add(username);
		un.add(sector);

		anagrafica.setText("Utente: ");
		flab.setText(Database.Utente.getFirstname()+" "+Database.Utente.getSecondname());
		anag.setLayout(new BoxLayout(anag,BoxLayout.Y_AXIS));
		anag.add(anagrafica);
		anag.add(flab);

		div.setLayout(new BoxLayout(div, BoxLayout.Y_AXIS));
		div.add(un);
		div.add(Box.createVerticalStrut(10));
		div.add(anag);
		div.add(Box.createVerticalStrut(10));
		div.add(gestAccount);
		div.add(logout);

		profile.setLayout(new BoxLayout(profile,BoxLayout.X_AXIS));
		profile.setAlignmentY(CENTER_ALIGNMENT);
		profile.setAlignmentX(CENTER_ALIGNMENT);
		profile.add(photo);
		profile.add(div);
		profile.setMinimumSize(new Dimension(350, 150));
		profile.setPreferredSize(new Dimension(350, 150));
		profile.setMaximumSize(new Dimension(350, 150));
		profile.setVisible(true);
	}
	@Override
	public void update(Observable o, Object arg) {
		profile.removeAll();
		startHomeProfile();
		profile.repaint();
		profile.validate();
	}

}
